<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2016/9/22
 * Time: 9:47
 *订单管理
 */

require('../include/init.inc.php');
$method = $id = $order_sn = $action = $color = $size = $num = $addr = $username = $phone = $email = '';
extract($_REQUEST, EXTR_IF_EXISTS);


if (Common::isPost() && $action == 'update_prod_info') {
    Common::checkParam($order_sn);
    $Order = AdminOrder::getByOrderSn($order_sn);
    if (empty($Order)) {
        Common::exitWithError(ErrorMessage::ORDER_NOT_EXIST, "one_page_shop/order_edit_display.php");
    }


    $update_data = array("size" => $size, "color" => $color, "num" => $num, "modifytime" => time());
    $result = AdminShopCart::update($order_sn, $update_data);
    $order_up_data = array("user_name" => $username, "phone" => $phone, "addres" => $addr, "email" => $email, "modifytime" => time());
    $result = AdminOrder::updateBySn($order_sn, $order_up_data);


    if ($result) {
        SysLog::addLog(UserSession::getUserName(), 'Update', 'OrderEdit', $order_sn, json_encode($update_data));
        Common::exitWithSuccess('修改完成', 'one_page_shop/order.php');
    } else {
        OSAdmin::alert("error");
    }
}

if (Common::isGet() && $action == 'del') {
    Common::checkParam($id);
    $rt = AdminOrder::delete($id);
    if ($rt) {
        $res = AdminShopCart::delete($id);
        if ($res) {
            SysLog::addLog(UserSession::getUserName(), 'Del', 'OrderDel', $order_sn, $order_sn);
            Common::exitWithSuccess('删除完成', 'one_page_shop/order.php');
        } else {
            OSAdmin::alert("error");
        }
    }
}
$confirm_html = OSAdmin::renderJsConfirm("icon-remove");
Template::assign('osadmin_action_confirm', $confirm_html);
Template::display('one_page_shop/kuaidi.tpl');